﻿using Ken_WPF_UI.Common;
using Ken_WPF_UI.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Ken_WPF_UI.View
{
    /// <summary>
    /// ListBoxWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ListBoxWindow : Window
    {
        public List<ClassInfo> list = DataUtil.GetMyList(false);

        public ListBoxWindow()
        {
            InitializeComponent();
        }


        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //方式一 非绑定
            this.listBox.DisplayMemberPath = "Name";//显示 对应的属性名 
            this.listBox.SelectedValuePath = "Code";//实际值  对应的属性名
            list.ForEach(item => { this.listBox.Items.Add(item); });

            //方式二 使用ItemsSource进行绑定
            //list.ForEach(item => { this.listBox.Items.Add(item); });
            this.bindListBox1.ItemsSource = list;
            this.bindListBox1.DisplayMemberPath = "Name";//显示 对应的属性名 
            this.bindListBox1.SelectedValuePath = "Code";//实际值  对应的属性名

            //方式三 使用DataContext进行绑定 针对的标签里面的ItemsSource需要设置为{Binding}
            this.bindListBox2.DataContext = list;
            this.bindListBox2.DisplayMemberPath = "Name";//显示 对应的属性名 
            this.bindListBox2.SelectedValuePath = "Code";//实际值  对应的属性名
        }
    }
}
